package com.cos.openapi.web.controller;

import com.cos.openapi.entity.Menu;
import com.cos.openapi.entity.Role;
import com.cos.openapi.pojo.JsonResult;
import com.cos.openapi.pojo.TableResult;
import com.cos.openapi.services.MenuServices;
import com.cos.openapi.services.RoleServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: COS
 * @time: 2021/2/2 8:55
 * @description:
 */
@RestController
@RequestMapping("/sys/role")
public class RoleController {
    @Autowired
    private RoleServices roleServices;
    @Autowired
    private MenuServices menuServices;
    @RequestMapping("/table")
    public TableResult table(Integer page,Integer limit,String name){
        return roleServices.table(page,limit,name);
    }

    @RequestMapping("/update")
    public JsonResult updateStatus(Integer id,Integer status){
        return roleServices.updateStatus(id,status);
    }

    @RequestMapping("/role_menu")
    public List<Integer> roleMenu(Integer roleId){
        return roleServices.roleMenu(roleId);
    }
    @RequestMapping("/menu_tree")
    public List<Menu> menuTree(){
        return menuServices.menuTree();
    }

    @RequestMapping("/assign_menu")
    public JsonResult assignMenu(Integer roleId,Integer[] menuIds){
        return roleServices.assignMenu(roleId,menuIds);
    }

    @RequestMapping("/updateRole")
    public JsonResult updateRole(Role role){
        return roleServices.updateRole(role);
    }
}
